package yy.com.yjbotouch;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yy.com.yjbotouch.util.MyCustomLayout;

public class MainActivity extends AppCompatActivity implements View.OnTouchListener{

    @Bind(R.id.skip_activity)
    TextView skipActivity;

    MyCustomLayout layout;
    LayoutAnimationController layoutAnimationController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        layout = (MyCustomLayout) findViewById(R.id.layout);

        AnimationSet set = new AnimationSet(true);

        AlphaAnimation a = new AlphaAnimation(0f, 1f);
        a.setDuration(500);
        TranslateAnimation t = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
        t.setDuration(500);

        set.addAnimation(t);
        set.addAnimation(a);
        layoutAnimationController = new LayoutAnimationController(set);
        layout.setLayoutAnimation(layoutAnimationController);

    }


    @OnClick(R.id.skip_activity)
    public void onClick() {
        startActivity(new Intent(MainActivity.this, TouchActivity.class));
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d("yjbo-Mainac-onTou-",event.getAction()+"--"+super.onTouchEvent(event));
        return super.onTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.d("yjbo-Mainac-dispa-",ev.getAction()+"--"+super.onTouchEvent(ev));
        return super.dispatchTouchEvent(ev);//这样还会往MyCustomLayout里面执行操作了
//        return  onTouchEvent(ev);//这样就不会往MyCustomLayout里面执行操作了
    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }
}
